package com.loe.mvp

import android.os.Bundle
import androidx.fragment.app.Fragment
import com.loe.mvp.ext_app.addFragment
import com.loe.mvp.ext_app.intentStringExtra
import com.loe.mvp.ext_java.safe
import com.loe.mvp.util.LoeRouter
import kotlinx.android.synthetic.main.activity_fragment_path.*

/**
 * fragment路由Activity
 */
class FragmentPathActivity : BaseActivity()
{
    val fragPath by intentStringExtra("fragPath")

    val fragClass by intentStringExtra("fragClass")

    override fun onCreate(savedInstanceState: Bundle?)
    {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_fragment_path)

        safe()
        {
            val fragmentClass = if (fragClass.isNotEmpty())
            {
                Class.forName(fragClass) as Class<Fragment>
            } else
            {
                LoeRouter.getFragment(fragPath)
            }

            val fragment = fragmentClass.newInstance()
            fragment.arguments = intent.extras
            addFragment(viewContent, fragment)

        }
    }
}